// 引入react
import * as React from 'react';
import {StyleSheet, View, Text, ScrollView, Dimensions, TouchableOpacity,Image,ImageBackground} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import AllStyle from '../../../../style';
import {HeaderTitle} from '../../../../componet/settingComponent/HeaderTitle';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {BottomButton} from '../../../../componet/settingComponent/BottomButton';
import {Loading} from '../../../../utils/Loading';
import {Toast} from '../../../../utils/Toast';
import {getFaceDatabaseInfo, getFaceDateInfoList, reviewFacePhotos} from '../../../../api/facedatabase';

/**
 * @Description:
 * @author TangYong
 * @date 2023/3/13
 */
export class PhotoReview extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            user:{
                faceDatabaseEntity: {
                    url:null
                },
            },
            id:this.props.route.params.id,
        };
    }

    //生命周期：组件挂载后
    componentDidMount() {
        this.init()
    }

    //方法
    init=()=>{
        Loading.show()
        getFaceDatabaseInfo(this.state.id).then(res=>{
            console.log(JSON.stringify(res));
            Loading.hidden()
            let {userEntity}=res
            this.setState({user:userEntity})
        }).catch(err=>{
            Toast.showWarning(err.toString())
            Loading.hidden()
        }).finally(()=>{
            Loading.hidden()

        })
    }

    //方法
    back = () => {
        const route = {

            name: this.props.route.params.routePathName,
            params: {
                title: '人脸审核',
            },
        };
        this.props.navigation.navigate(route);
         //this.props.navigation.goBack();

    };
    goto = (name, params) => {

        const route = {
            name: name,
            params: {
                routePathName: this.props.route.name,
                ...params,
            },

        };
        this.props.navigation.navigate(route);
    };
    saveOrFail=(val)=>{
        let data={
            status:val,
            id:this.state.id
        }
        reviewFacePhotos(data).then(res=>{
            this.back()
        }).catch(err=>{
            Toast.showWarning(err.toString())
            Loading.hidden()

        }).finally(()=>[
            Loading.hidden()
        ])
    }

    //DOM
    render() {
        return (
            <SafeAreaView edges={['top', 'left', 'right', 'bottom']} style={{flex: 1, backgroundColor: '#FFF'}}>
                <View style={AllStyle.container}>
                    <HeaderTitle goBack={() => this.back()} headtitle={this.props.route.params.title}></HeaderTitle>
                    <ScrollView style={{padding: 15}}>

                        <View style={{alignItems: 'center'}}>
                            <Text style={{fontSize: 26}}>{this.state.user.username}</Text>
                        </View>
                        <View style={style.imgBody}>
                            <ImageBackground
                                style={style.img}
                                source={{uri:this.state.user.faceDatabaseEntity.url}}
                            />
                        </View>
                        <View style={{alignItems: 'center'}}>
                            <Text style={{fontSize: 20}}>
                                请确认照片是不是员工本人
                            </Text>
                        </View>
                    </ScrollView>
                </View>
                <View style={style.bottom}>
                    <TouchableOpacity
                        style={style.button}
                        onPress={() => {
                            this.saveOrFail(0);
                        }}
                    >
                        <Text style={style.buttonText}>{'不通过'}</Text>
                    </TouchableOpacity>
                    <TouchableOpacity
                        style={[style.button, {
                            marginLeft: 10, backgroundColor: '#409EFF', borderWidth: 0,
                        }]}
                        onPress={() => {
                            this.saveOrFail(1);
                        }}
                    >
                        <Text style={style.buttontongguo
                        }>{'审核通过'}</Text>
                    </TouchableOpacity>


                </View>
            </SafeAreaView>

        );
    }

}

const width = Dimensions.get('window').width;
const style = StyleSheet.create({
    //样式
    cardContainer: {
        marginLeft: -15,
        paddingLeft: 10,
        //backgroundColor: 15,
        flexDirection: 'row',
        width: width,
        flexWrap: 'wrap',

    },
    imgBody:{
       // backgroundColor:'#999',
        width:width-30,
        marginBottom:20,
        marginTop:20,
        //justifyContent: 'center',
         alignItems: 'center',

    },
    img: {
        width: width - 30 - 80,
        height:width-30-80,
       // backgroundColor: 'red',
        borderRadius: 10,

    },
    button: {
        alignItems: 'center',
        justifyContent: 'center',
        //backgroundColor: '#409EFF',
        borderWidth: 1,
        borderColor: '#ECEEEF',
        width: (width - 30) / 2,
        height: 40,
        borderRadius: 12,
    },
    bottom: {
        padding: 10,
        width: width,
        backgroundColor: '#fff',
        flexDirection: 'row',
    },
    buttonText: {
        //color: '#FEFEFE',
        fontWeight: '500',
        fontSize: 16,
    },
    buttontongguo: {
        color: '#FEFEFE',
        fontWeight: '500',
        fontSize: 16,
    },

});

